/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Rota;

import java.awt.geom.Point2D;
import java.util.ArrayList;

/**
 *
 * @author Administrador
 */
public class Mapa {

    public ArrayList<Point2D> mapa = new ArrayList<Point2D>();
    double distsEntrePontos[][];

    public Mapa() {
    }

    public double[][] getDistsEntrePontos() {
        return distsEntrePontos;
    }

    public ArrayList<Point2D> getMapa() {
        return mapa;
    }

    public void clear() {
        mapa.clear();
    }

    public void add(Point2D a, int index) {
        this.mapa.add(index, a);
    }
    
    public Point2D get(int index){
        return this.mapa.get(index);
    }



    public double calculaDist(Point2D a, Point2D b) {
//        double distReal = Math.sqrt(Math.pow(a.getX() - b.getX(), 2) + Math.pow((a.getY() - b.getY()), 2));
        //O random faz com que a distancia n seja proporcional
        //p todas as cidades (adcionando obstaculos hehehe)
        return (Math.random() * 1000 * mapa.size());
    }

    public double[][] mapeiaDists() {
        int tamanho = (int) Math.pow(mapa.size(), 2);
        distsEntrePontos = new double[tamanho][tamanho];
        for (int cont = 0; cont < mapa.size(); cont++) {
            for (int cont2 = 0; cont2 < mapa.size(); cont2++) {
                if(cont == cont2) distsEntrePontos[cont][cont2] = 0;
                else distsEntrePontos[cont][cont2] = calculaDist(mapa.get(cont), mapa.get(cont2));
            }
        }
        return distsEntrePontos;
    }

    public double getDist(int a, int b) {
        return distsEntrePontos[a][b];
    }

    public void imprimiMatrizDist() {
        for (int cont = 0; cont < mapa.size(); cont++) {
            for (int cont2 = 0; cont2 < mapa.size(); cont2++) {
                System.out.println(cont + "->" + cont2 + " = " + getDist(cont, cont2));
            }
        }
    }
}
